package cn.com.websocket.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/***
 ** @category 正则表达式工具类
 ** @author qing.yunhui
 ** @email: qingyh@glodon.com
 ** @createTime: 2021-08-16 14:20
 **/
public class RegularExpressionUtil {

    /**
     * <p>base64文件编码格式</p>
     * */
    public static final Pattern base64Pattern = Pattern.compile("data:([\\S]{1,});base64,");

    /**
     * <p>根据给定base64File截取base64前缀</p>
     * @param base64File
     * @return
     * */
    public static String findBase64FilePrefix(String base64File){
        Matcher matcher = base64Pattern.matcher(base64File);
        if(matcher.find()){ return matcher.group(); }
        return null;
    }


    public static void main(String[]args){

        // /^(0([.][0-9]{2}))$/
        Pattern pattern2 = Pattern.compile("/^(0([.][0-9]{2}))$/");













        Pattern pattern = Pattern.compile("data:([\\S]{1,});base64,");
        Matcher matcher = pattern.matcher("data:application/x-zip-compressed;base64,dfdsfddsfdfdsfs");
        String base64PNG ="";
        String base64Zip ="data:application/x-zip-compressed;base64,fasdfasfdasdfefsdafasddfasdfa";
        Matcher matcher2 = pattern.matcher(base64PNG);
        Matcher matcher3 = pattern.matcher(base64Zip);
        System.out.println(matcher.find());
        System.out.println(matcher.group());
        System.out.println(matcher2.find());
        System.out.println(matcher2.group());
        System.out.println(matcher3.find());
        System.out.println(matcher3.group());
    }

}
